package sh.service.impl;

import sh.orm.SessionFactory;
import sh.orm.query.Condition;
import sh.orm.query.ConditionConst;
import sh.orm.query.QueryCondition;
import sh.model.Message;
import sh.service.MessageService;

import java.util.List;


public class MessageServiceImpl implements MessageService {

	@Override
	public List<Message> getByUserId(Long userId){
		QueryCondition queryCondition = new QueryCondition();
		Condition condition = new Condition(Message.SELLER_ID , ConditionConst.EQUAL , userId);
		queryCondition.add(condition);
		return SessionFactory.getInstance().getSession().selectByQueryCondition(queryCondition ,Message.class);
	}

	@Override
	public boolean sendMessage(Long seller,Long buyer,String message)  {
		Message msg = new Message();
		msg.setSellerId(seller);
		msg.setBuyerId(buyer);
		msg.setMessage(message);
		SessionFactory.getInstance().getSession().save(msg);
		return true;
	}

}
